package com.easylinkin.linkappapi.facerecognition.config;

import com.easylinkin.linkappapi.facerecognition.service.rest.BaiduManagementClientService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

@ConditionalOnProperty(value = "ai.face.platform", havingValue = "baidu")
@Configuration
public class BaiduRestClientConfig {

    @Value("${ai.face.baidu.management}")
    private String faceManagementUrl;


    @Bean
    public BaiduManagementClientService baiduManagementClient() {

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(faceManagementUrl.endsWith("/") ? faceManagementUrl : (faceManagementUrl + "/"))
                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        return retrofit.create(BaiduManagementClientService.class);
    }
}
